<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>快递收寄</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <style type="text/css">
        .icon {
            width: 1em;
            height: 1em;
            vertical-align: -0.15em;
            fill: currentColor;
            overflow: hidden;
        }
    </style>
    <script src="__TMPL__/public/assets/wuye/js/mui.min.js"></script>
    <link href="__TMPL__/public/assets/wuye/css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/wuye/css/app.css" />
    <script src="__TMPL__/public/assets/wuye/js/iconfont.js"></script>
    <link href="__TMPL__/public/assets/wuye/css/mui.picker.css" rel="stylesheet" />
    <link href="__TMPL__/public/assets/wuye/css/mui.poppicker.css" rel="stylesheet" />
    <style type="text/css">
        .mui-card-header>img:first-child{
            height: 80px;
            width: 80px;
        }
        .mui-card-header.mui-card-media .mui-media-body {
            font-size: 20px;
            font-weight: 500;
            line-height: 40px;
            margin-bottom: 0;
            margin-left: 120px;
            color: #333;
        }
        .mui-input-row .mui-btn{
            width: 100%;
        }
        #kuaidi{
            margin-top: 15px;
        }
        .mui-ellipsis {
            overflow: hidden;
            white-space: normal;
            text-overflow: ellipsis;
        }
        .icon{
            color: red;
        }
    </style>
</head>

<body>

<header class="mui-bar mui-bar-nav">
    <a class="mui-icon mui-icon-left-nav mui-pull-left" href="javascript:window.history.go(-1);"></a>
    <h1 class="mui-title">快递收寄</h1>
</header>
{:widget('Wuye/nav')}
<div class="mui-content">
    <div class="mui-card">
        {:widget('Wuye/info')}
    </div>

    <div class="mui-button-row">
        <a href="{:url('portal/Wuye/expressyuyue')}" type="button" class="mui-btn mui-btn-primary" style="margin: 0 0 10px 0;width: 95%;padding: 10px;">我要发快递</a>
    </div>

    <form class="mui-input-group">
        <div class="mui-input-row">
            <button id='showUserPicker' class="mui-btn mui-btn-block" type='button'>选择物流</button>
        </div>
        <div class="mui-input-row">
            <label>快递单号</label>
            <input type="text" class="mui-input-clear" placeholder="请输入快递单号" id="danhao">
        </div>
        <div class="mui-button-row">
            <button type="button" class="mui-btn mui-btn-primary" onclick="chauxn();">快递跟踪</button>
        </div>
    </form>

    <ul class="mui-table-view" id="kuaidi"></ul>
</div>
</body>
<script src="__TMPL__/public/assets/wuye/js/mui.picker.js"></script>
<script src="__TMPL__/public/assets/wuye/js/mui.poppicker.js"></script>
<script>
    (function($, doc) {
        $.init();
        $.ready(function() {
            var _getParam = function(obj, param) {
                return obj[param] || '';
            };
            var userPicker = new $.PopPicker();
//            更多快递查询可以对应/thinkcmf-5.0.170927/simplewind/vendor/express/ExpressCode.xls自行添加
            userPicker.setData([{value: 'EMS',text: 'EMS'},{value: 'STO',text: '申通快递'},{value: 'YTO',text: '圆通速递'},{value: 'YD',text: '韵达快递'},{value: 'ZTO',text: '中通速递'},{value: 'ZJS',text: '宅急送'},{value: 'SF',text: '顺丰快递'},{value: 'HHTT',text: '天天快递'},{value: 'BTWL',text: '百世快运'},{value: 'RFD',text: '如风达'}]);
            var showUserPickerButton = doc.getElementById('showUserPicker');
            var userResult = doc.getElementById('userResult');
            showUserPickerButton.addEventListener('tap', function(event) {
                userPicker.show(function(items) {
//                    showUserPickerButton.innerText = JSON.stringify(items[0].text);
                    var text = JSON.stringify(items[0].text);
                    value = JSON.stringify(items[0].value);
                    text = text.replace(/\"/g, "");
                    value = value.replace(/\"/g, "");
                    showUserPickerButton.innerText = text;
                    //返回 false 可以阻止选择框的关闭
                    //return false;
                });
            }, false);
        });
    })(mui, document);

    function chauxn() {
        var dhText = document.getElementById('danhao').value;
        mui.ajax("{:url('portal/wuye/show_order1')}",{
            data:{
                dhText:dhText
            },
            dataType:'json',//服务器返回json格式数据
            type:'post',//HTTP请求类型
            timeout:10000,//超时时间设置为10秒；
            headers:{'Content-Type':'application/json'},
            success:function(data){
                //服务器返回响应，根据响应结果，分析是否登录成功；
                console.log(data);
                if(data['Success'] != false){
                    var showUserPickerButton = document.getElementById('showUserPicker');
                    showUserPickerButton.innerText = data['Shippers']['0']['ShipperName'];
                    if(data['Shippers']['0']['ShipperCode'] != ''){
                        value = data['Shippers']['0']['ShipperCode'];
                    }
                    var dhText = document.getElementById('danhao').value;

                    mui.ajax("{:url('portal/wuye/show_order')}",{
                        data:{
                            value:value,dhText:dhText
                        },
                        dataType:'json',//服务器返回json格式数据
                        type:'post',//HTTP请求类型
                        timeout:10000,//超时时间设置为10秒；
                        headers:{'Content-Type':'application/json'},
                        success:function(data){
                            //服务器返回响应，根据响应结果，分析是否登录成功；
//                console.log(data['Traces']);
                            var array = data['Traces'];
                            var kdUl = document.getElementById('kuaidi');
                            var html = '';
                            for(var i = array.length-1;i>=0;i--){
                                    console.log(array[i]);
                                html += "<li class='mui-table-view-cell mui-media'>\n" +
                                    "            <a href=\"javascript:;\">\n" +
                                    "                <svg aria-hidden=\"true\" class=\"icon mui-media-object mui-pull-left\">\n" +
                                    "                    <use xlink:href=\"#icon-kuaidi11\"></use>\n" +
                                    "                </svg>\n" +
                                    "                <div class=\"mui-media-body\">\n" +
                                    "                    "+array[i]['AcceptTime'] +"\n" +
                                    "                    <p class='mui-ellipsis'>"+array[i]['AcceptStation']+"</p>\n" +
                                    "                </div>\n" +
                                    "            </a>\n" +
                                    "        </li>";
                                kdUl.innerHTML = html;
                            }
                        },
                        error:function(xhr,type,errorThrown){
                            //异常处理；
                            console.log(type);
                        }
                    });
                }
            },
            error:function(xhr,type,errorThrown){
                //异常处理；
                console.log(11111111);
                console.log(type);
            }
        });
    }
</script>
</html>